class NotifyAdvInfoCmd {
  final int opCodeSn;
  final String name;
  final int opCode;
  final Param param;
  final int status;
  final int type;

  NotifyAdvInfoCmd({
    required this.opCodeSn,
    required this.name,
    required this.opCode,
    required this.param,
    required this.status,
    required this.type,
  });

  factory NotifyAdvInfoCmd.fromMap(Map<String, dynamic> map) {
    return NotifyAdvInfoCmd(
      opCodeSn: (map['OpCodeSn'] ?? 0).toInt(),
      name: map['name'] ?? '',
      opCode: (map['opCode'] ?? 0).toInt(),
      param: Param.fromMap(Map<String, dynamic>.from(map['param'] ?? {})),
      status: (map['status'] ?? 0).toInt(),
      type: (map['type'] ?? 0).toInt(),
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'OpCodeSn': opCodeSn,
      'name': name,
      'opCode': opCode,
      'param': param.toMap(),
      'status': status,
      'type': type,
    };
  }
}

class Param {
  final int action;
  final int chargingBinQuantity;
  final int connectWay;
  final int deviceType;
  final String edrAddr;
  final bool isDeviceCharging;
  final bool isLeftCharging;
  final bool isRightCharging;
  final bool isSupportChargingCase;
  final int leftDeviceQuantity;
  final int pid;
  final int rightDeviceQuantity;
  final int seq;
  final bool showDialog;
  final int uid;
  final int version;
  final int vid;
  final int xmOpCode;

  Param({
    required this.action,
    required this.chargingBinQuantity,
    required this.connectWay,
    required this.deviceType,
    required this.edrAddr,
    required this.isDeviceCharging,
    required this.isLeftCharging,
    required this.isRightCharging,
    required this.isSupportChargingCase,
    required this.leftDeviceQuantity,
    required this.pid,
    required this.rightDeviceQuantity,
    required this.seq,
    required this.showDialog,
    required this.uid,
    required this.version,
    required this.vid,
    required this.xmOpCode,
  });

  factory Param.fromMap(Map<String, dynamic> map) {
    return Param(
      action: (map['action'] ?? 0).toInt(),
      chargingBinQuantity: (map['chargingBinQuantity'] ?? 0).toInt(),
      connectWay: (map['connectWay'] ?? 0).toInt(),
      deviceType: (map['deviceType'] ?? 0).toInt(),
      edrAddr: map['edrAddr'] ?? '',
      isDeviceCharging: map['isDeviceCharging'] ?? false,
      isLeftCharging: map['isLeftCharging'] ?? false,
      isRightCharging: map['isRightCharging'] ?? false,
      isSupportChargingCase: map['isSupportChargingCase'] ?? false,
      leftDeviceQuantity: (map['leftDeviceQuantity'] ?? 0).toInt(),
      pid: (map['pid'] ?? 0).toInt(),
      rightDeviceQuantity: (map['rightDeviceQuantity'] ?? 0).toInt(),
      seq: (map['seq'] ?? 0).toInt(),
      showDialog: map['showDialog'] ?? false,
      uid: (map['uid'] ?? 0).toInt(),
      version: (map['version'] ?? 0).toInt(),
      vid: (map['vid'] ?? 0).toInt(),
      xmOpCode: (map['xmOpCode'] ?? 0).toInt(),
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'action': action,
      'chargingBinQuantity': chargingBinQuantity,
      'connectWay': connectWay,
      'deviceType': deviceType,
      'edrAddr': edrAddr,
      'isDeviceCharging': isDeviceCharging,
      'isLeftCharging': isLeftCharging,
      'isRightCharging': isRightCharging,
      'isSupportChargingCase': isSupportChargingCase,
      'leftDeviceQuantity': leftDeviceQuantity,
      'pid': pid,
      'rightDeviceQuantity': rightDeviceQuantity,
      'seq': seq,
      'showDialog': showDialog,
      'uid': uid,
      'version': version,
      'vid': vid,
      'xmOpCode': xmOpCode,
    };
  }
}
